<template>
  <div class="about">
    <header>
       <span @click="$router.back()">返回</span>
       <section>
         购物清单
       </section>
       <span></span>
    </header>
    <ul>
      <li v-for="(item,index) in cartList" :key="index">
        <input type="checkbox" v-model="item.check" @change="boxChange">
        <img src="../assets/img.png" alt="">
        <section>
          <h4>{{item.name}}</h4>
          <p>￥{{item.price}}</p>
        </section>
        <div>
          <p @click="item.buyNum++">+</p>
          <p>{{item.buyNum}}</p>
          <p @click="item.buyNum==1?item.buyNum=1:item.buyNum--">-</p>
        </div>
      </li>
    </ul>
    <div class="foot">
       <span style="margin-left:10px" @click="delect"><input type="checkbox" v-model="checked" @change="allCheck(checked)"> 删除所选</span>
       <span>合计：￥{{allPrice}}</span>
       <span class="right">去结算({{allNum}})</span>
    </div>
  </div>
</template>
<script>
import { mapState,mapMutations,mapGetters } from 'vuex';
export default {
  data(){
    return {
      checked: false
    }
  },
  computed:{
    ...mapState(['cartList']),
    ...mapGetters(['allPrice','allNum'])
  },
  methods: {
    ...mapMutations(['allCheck','delect']),
    boxChange(){ // 反选的事件
      // this.cartList 购物车的数据 
      this.checked = this.cartList.every(item => item.check);
    }
  },
}
</script>

<style lang="scss" scoped>
.about{
  height: 100%;
  background: #e9e9e9;
  header{
    background: #fff;
    height: 50px;
    display: flex;
    align-items: center;
    span{
      width: 60px;
      text-align: center;
    }
    section{
      flex: 1;
      text-align: center;
    }
  }
  ul{
    height: calc(100% - 100px);
    overflow: auto;
  }
  li{
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    background: #fff;
    margin-top: 10px;
    img{
      width: 60px;
      margin: 0 10px;
    }
    section{
      flex: 1
    }
  }
  .foot{
    height: 50px;
    display: flex;
    background: #fff;
    align-items: center;
    justify-content: space-between;
    .right{
      background: #440f7d;
      color: #fff;
      height: 100%;
      line-height: 50px;
      padding: 0 10px;
    }
  }
}
</style>

